/**
 * 1759. 统计同构子字符串的数目
 * @param {string} s
 * @return {number}
 */
var countHomogenous = function (s) {
	let res = 0
	for (let i = 0; i < s.length; ) {
		let j = i + 1
		while (j < s.length && s[j] === s[i]) {
			j++
		}
		const str = s.slice(i, j)
		res += getSum(str.length)
		i = j
	}
	const MAX = 10 ** 9 + 7
	res %= MAX
	return res
}
const getSum = (num) => {
	let sum = 0
	while (num > 0) {
		sum += num
		num--
	}
	return sum
}

// 数学
var countHomogenous = function (s) {
	const MOD = 1000000007
	let res = 0
	let prev = s[0]
	let cnt = 0
	for (let i = 0; i < s.length; i++) {
		const c = s[i]
		if (c === prev) {
			cnt++
		} else {
			res += ((cnt + 1) * cnt) / 2
			cnt = 1
			prev = c
		}
	}
	res += ((cnt + 1) * cnt) / 2
	return res % MOD
}
const res = countHomogenous('zzzzz')
console.log('countHomogenous :>>', res)
